//go:build wireinject

package main

import (
	"gitee.com/chicken-c/go-learn/webook/internal/events/article"
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory"
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory/cache"
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory/dao"
	"gitee.com/chicken-c/go-learn/webook/internal/service"
	"gitee.com/chicken-c/go-learn/webook/internal/web"
	"gitee.com/chicken-c/go-learn/webook/internal/web/jwt"
	"gitee.com/chicken-c/go-learn/webook/ioc"
	"github.com/google/wire"
)

var rankSvcSet = wire.NewSet(
	cache.NewRedisRankingCache,
	repostiory.NewCachedRankingRepostiory,
	service.NewBatchRankingService,
)

func InitWebServer() *App {
	wire.Build(
		//第三方依赖
		ioc.InitDB, ioc.InitRedis,
		ioc.InitLogger,
		ioc.InitSaramaClient,
		ioc.InitSyncProducer,

		//dao
		dao.NewUserDao,
		dao.NewGORMArticleDAO,
		dao.NewGORMInterActiveDAO,

		//cache
		cache.NewRedisCodeCache, cache.NewUserCache,
		cache.NewRedisArticleCache,
		cache.NewRedisInterActiveCache,

		//repo
		repostiory.NewCachedUserRepository, repostiory.NewCachedCodeRepository,
		repostiory.NewCachedArticleRepostiory,
		repostiory.NewCachedInterActiveRepository,

		//service
		ioc.InitSMSService,
		ioc.InitWechatService,
		service.NewuserService, service.NewcodeService,
		service.NewArticleService,
		service.NewInterActiceService,

		ioc.InitJobs,
		ioc.InitRankingJob,
		rankSvcSet,

		//kafka生产者和消费者
		article.NewSaramaSyncProducer,
		article.NewInteractiveReadEventConsumer,
		ioc.InitConsumers,

		//userHandle
		web.NewUserHandler,
		web.NewOAuto2WechatHandler,
		jwt.NewRedisJWTHandler,
		web.NewArticleHandler,

		//gin middleware
		ioc.GinMiddlewares, //需要传入redis.Cmdable
		//集合所有的中间件和handler注册路由
		ioc.InitWebServer, //需要传入[]gin.HandlerFunc 也就是我们的use()middleware

		wire.Struct(new(App), "*"),
	)

	//返回值我们随便返回，wire只需要知道类型就行
	return new(App)
}
